package cn.com.common.tools;

import java.time.*;
import java.util.Date;

public class DateConvert {
	// 01. java.util.Date --> java.time.LocalDateTime
	public static LocalDateTime UDateToLocalDateTime(Date date) {
	    Instant instant = date.toInstant();
	    ZoneId zone = ZoneId.systemDefault();
	    return LocalDateTime.ofInstant(instant, zone);
	}

	// 02. java.util.Date --> java.time.LocalDate
	public static LocalDate UDateToLocalDate(Date date) {
	    Instant instant = date.toInstant();
	    ZoneId zone = ZoneId.systemDefault();
	    LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
	    return localDateTime.toLocalDate();
	}

	// 03. java.util.Date --> java.time.LocalTime
	public static LocalTime UDateToLocalTime(Date date) {
	    Instant instant = date.toInstant();
	    ZoneId zone = ZoneId.systemDefault();
	    LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
	    return localDateTime.toLocalTime();
	}


	// 04. java.time.LocalDateTime --> java.util.Date
	public static Date LocalDateTimeToUdate(LocalDateTime localDateTime) {
	    ZoneId zone = ZoneId.systemDefault();
	    Instant instant = localDateTime.atZone(zone).toInstant();
	    return Date.from(instant);
	}


	// 05. java.time.LocalDate --> java.util.Date
	public static Date LocalDateToUdate(LocalDate localDate) {
	    ZoneId zone = ZoneId.systemDefault();
	    Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
	    return Date.from(instant);
	}

	// 06. java.time.LocalTime --> java.util.Date
	public static Date LocalTimeToUdate(LocalTime localTime) {
	    LocalDate localDate = LocalDate.now();
	    LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
	    ZoneId zone = ZoneId.systemDefault();
	    Instant instant = localDateTime.atZone(zone).toInstant();
	    return Date.from(instant);
	}
}
